<%@ page language="java" pageEncoding="utf-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<title>广东省传播平台-物料编辑页</title>
		<style>
		#organizesTree {
			margin-top: 10px;
			border: 1px solid #617775;
			background: #f0f6e4;
			min-width: 180px;
			max-height: 400px;
			overflow-y: scroll;
			overflow-x: auto;
		}
		</style>
		<link rel="stylesheet" type="text/css" href="<%=path%>/css/tag.css" />
		<link rel="stylesheet" type="text/css" href="<%=path%>/css/common.css" />
        <script type="text/javascript" src="<%=path%>/js/My97DatePicker/WdatePicker.js"></script>
		<link rel="stylesheet" type="text/css" href="<%=path%>/css/tag.css" />
		<link type="text/css" rel="stylesheet" href="<%=path%>/css/zTreeStyle/zTreeStyle.css" />	
		<link type="text/css" href="<%=path%>/js/jquery-ui-1.8.21.custom/css/smoothness/jquery-ui-1.8.21.custom.css" rel="stylesheet" />
		<script type="text/javascript" src="<%=path%>/js/jquery-1.7.2.js"></script>
		<script type="text/javascript" src="<%=path%>/js/jquery.ztree.core-3.1.js"></script>
		<script type="text/javascript" src="<%=path%>/js/jquery.ztree.excheck-3.1.min.js"></script>
		<script type="text/javascript" src="<%=path%>/js/jquery-ui-1.8.21.custom/js/jquery-ui-1.8.21.custom.min.js"></script>
		<script type="text/javascript">
	    function doSubmit(url) {
		    document.forms[0].action = url;
		    document.forms[0].submit();
		    //document.getElementById("frmID").submit();
	    }
	   
	    function deleteMaterial(materialContent) {
		if (confirm('确定删除此物料文件？')) {
		var url = encodeURI(encodeURI("delContentAction.action?materialContent=" +materialContent));
			$.ajax({
				url : url,
				type : "POST",
				cache : false,
				success : function(message) {
					 if (message == "error") 
					{
						window.location.href="materiallist.action";
					}
					 else if(message=="success"){
						alert("物料文件删除成功！");
					    $('#trID').empty();
					    $('#hidmaterialContent').val('');
					}
				}
			});
		 }
	 }
    function cancle(url)
    {
      if(confirm("您确认取消本次操作？"))
      {
         doSubmit(url);
      }

    }  
	    
	//下载文件
    function downloadFile(fileName)
     {
	      var url = encodeURI(encodeURI("downLoadMaterialFileName.action?fileName=" +fileName));
	      window.location.href=url;
     }
   function addSubFrm() {

	var myReg = /^[^@\/\'\\\"#$%&\^\*<>]+$/;

	//物料名称
	var tmpContractID = trim(document.getElementById("materialName").value);
	document.getElementById("materialName").value = tmpContractID;
	if (tmpContractID == '') {
		alert('物料名称不能为空！');
		return false;
	}
	if (getLen(tmpContractID)>100) {
		alert('物料名称的字符个数不允许超过100位（汉字33个）！');
		return false;
	}
	//上线时间
	var tmpContractName = trim(document.getElementById("firstUpTime").value);
	if (tmpContractName == '') {
		alert('最初上线时间不能为空！');
		return false;
	}
	//物料排序
	var tmpContractBName = trim(document.getElementById("orderCol").value);
	var pattern   =  /[^\d]/g;
	if (tmpContractBName == '') {
		alert('物料排序不能为空！');
		return false;
	}
	if(pattern.test(tmpContractBName))
	{
	    alert('物料排序请输入1~99之间的整数！');
		return false;
	}
	if(tmpContractBName<1||tmpContractBName>99)
	{
	    alert('物料排序请输入1~99之间的整数！');
	    return false;
	}
	//物料描述
	var tmpContractA = trim(document.getElementById("accessory").value);
		if(getLen(tmpContractA)>256){
		alert('物料描述的长度不允许超过256位(汉字85个)！');
		return false;
	}
	
	var tempMaterialName= document.getElementById("materialName").value;
	var tempMaterialType= document.getElementById("materialType").value;
	var tempMaterialOwnCity= document.getElementById("ownCity").value;
	var tempMaterialServiceType= document.getElementById("serviceType").value;
	var tempMaterialFirstuptime1= document.getElementById("firstUpTime").value;
	var tempMaterialFirstuptime2= document.getElementById("firstUpTime").value;
	tempMaterialFirstuptime1 = tempMaterialFirstuptime1.substr(2,2);
	tempMaterialFirstuptime2 = tempMaterialFirstuptime2.substr(5,2);
	var tempMaterialFirstuptime = tempMaterialFirstuptime1+tempMaterialFirstuptime2;
	var tempMaterialOrderCol= document.getElementById("orderCol").value;
	if(tempMaterialOrderCol<10)
	{
	   tempMaterialOrderCol = "0"+tempMaterialOrderCol;
	}
	
	var tempMaterial1 =tempMaterialOwnCity+"-"+tempMaterialServiceType+"-"+tempMaterialType+"-"+tempMaterialFirstuptime+"-"+tempMaterialOrderCol+"-"+tempMaterialName;
	var tempMaterial2 = document.getElementById("materialID").value;
	
	var url = encodeURI(encodeURI('isExistEditMaterialID.action?tempMaterial1=' + tempMaterial1+'&tempMaterial2='+tempMaterial2));
		$.ajax( {
			url : url,
			type : "POST",
			cache : false,
			success : function(message) {
				if (message == "success") {
					alert("物料信息已存在！");
					$(this).focus();
				}else{
					doSubmit('toSaveEditAction.action');
				} 
			}
		});
	return  true;
}
function trim(str) {
	str = str.replace(/^\s*/, "");
	str = str.replace(/\s*$/, "");
	str = str.replace(/^[" "|"　"]*/, "");
	str = str.replace(/[" "|"　"]*$/, "");
	return str;
}
	 
	$(function(){
        //selectNav('nav8');
    });
    function getLen(str){
				var len=0;
				if(null!=str&&str!=""){
					for(var i=0;i<str.length;i++){
						var intCode=str.charCodeAt(i);
						//如果ASCII码等于34(")38(&)39(')47(/)60(<)62(>)92(\)也算三个字符
						if (intCode>=0&&intCode<=100&&intCode!=34&&intCode!=39&&intCode!=47&&intCode!=60&&intCode!=62&&intCode!=92){
							len=len+1;
						}else{
							len=len+3;
						}
					}
				}
				return len;
			}
</script>



	</head>

	<body>
		<!-- 顶栏start -->
		<jsp:include page="../common/top.jsp"></jsp:include>
		<!-- 顶栏end -->


		<!-- 顶部start -->
		<div id="main">
			<form id="materialEditForm" method="post" enctype="multipart/form-data">
			<input type="hidden" name="saveMaterialEdit.matId" id="materialEdit.matId" value="${materialEdit.matId}" />
			<input type="hidden" name="saveMaterialEdit.materialContent" id="hidmaterialContent" value="${materialEdit.materialContent}" />
				<div class="body">
				<!-- 导航菜单 -->
				<jsp:include page="../common/nav.jsp"></jsp:include>
				<!-- 主体 -->
				<div class="main_body">
				    <s:if test="%{null== materialEdit}">
					<div>
						<input type="button" class="btn-title" value="返回" 
                          onclick="doSubmit('materiallist.action');" />
					</div>
					&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
					</s:if>
					<div id="add_div">
						<table class="table_add" style="width: 100%;">
						<s:if test="%{null == materialEdit}">
							<tr>
								<th style="width: 150px; text-align: center;color: red;" colspan="3">
									该条记录不存在或已删除！ 									
								</th>
							</tr>
							</s:if>
							<s:else>
						
							<tr>
								<th style="width: 150px;">
									物料编号：
								</th>
								<td style="width: 227px;">
									<input type="text" class="text" readonly="readonly"
										style="width: 225px; line-height:22px; vertical-align:middle;" name="saveMaterialEdit.materialID" id="materialID" value="${materialEdit.materialID}" />
								</td>
								<th style="width: 189px;">
									物料名称：
								</th>
								<td style="width: 225px;">
									<input  type="text" class="text" name="saveMaterialEdit.materialName" id="materialName"
										style="width: 225px; line-height:22px; vertical-align:middle;" value="${materialEdit.materialName}" /><font color="red" >&nbsp;&nbsp; *</font>
								</td>
							</tr>
							
							
							
							<tr>
								<th style="width: 150px;">
									业务类型：
								</th>
								<td style="width: 225px;">
									<s:select  cssStyle="width: 227px;" name="saveMaterialEdit.serviceType" id="serviceType" value="materialEdit.serviceType" list="dataListWLYWLX"
										listKey="id" listValue="datavalue" >
								</s:select><font color="red" >&nbsp;&nbsp;*</font>
								</td>

								<th style="width: 189px;">
									物料类型：
								</th>
								<td style="width: 225px;">
									<s:select  cssStyle="width: 227px;" name="saveMaterialEdit.materialType" id="materialType" value="materialEdit.materialType" list="dataListWLLX"
										listKey="id" listValue="datavalue" >
								</s:select><font color="red" >&nbsp;&nbsp;*</font>
								</td>
							</tr>
							
							
							
							<tr>
								<th style="width: 150px;">
									归属地市：
								</th>
								<td>
								    <s:select cssStyle="width: 227px;" name="saveMaterialEdit.ownCity" id="ownCity" value="materialEdit.ownCity" list="dataListCITY"
										listKey="id" listValue="datavalue">
									</s:select><font color="red" >&nbsp;&nbsp;*</font>
									
								</td>
								<th style="width: 189px;">
									物料排序：
								</th>
								<td style="width: 225px;">
									<input style="width: 225px; line-height:22px; vertical-align:middle;" type="text" name="saveMaterialEdit.orderCol" id="orderCol"
										class="text" value="${materialEdit.orderCol}" /><font color="red" >&nbsp;&nbsp; *</font>
								</td>
								
							</tr>
							
							<tr>
								<th style="width: 150px;">
									最初上线时间：
								</th>
								<td style="width: 225px;">
									<input type="text" class="text Wdate" name="saveMaterialEdit.firstUpTime" id="firstUpTime" readonly="readonly"
									onfocus="WdatePicker({dateFmt:'yyyy-MM-dd'})"	style="width: 225px;" value="${materialEdit.firstUpTime}" />
									<font color="red" >&nbsp;&nbsp;*</font>
								</td>
								<th style="width: 189px;">
									物料级别：
								</th>
								<td style="width: 225px;">
									<s:select  cssStyle="width: 227px;" name="saveMaterialEdit.materialLevel" id="materialLevel" value="materialEdit.materialLevel" list="dataListWLJB"
										listKey="id" listValue="datavalue" >
								</s:select><font color="red" >&nbsp;&nbsp;*</font>
								</td>
								
							</tr>
							<tr>
							    <th style="width: 150px;">
									部门科室：
								</th>
								<td style="width: 225px;">
									<input type="hidden" id="orgID" name="saveMaterialEdit.ownDepartment" />
								    <input name="text2" type="text" class="text" id="showOrganize" value="${materialEdit.ownDepartment}"
										style="width: 225px; line-height:22px; vertical-align:middle;" onkeydown="if(event.keyCode==8)return false;"
										onclick="showMenu('showOrganize', 'organizeContent');" value="" readonly="readonly"/>
								</td>
							
							</tr>
							
							
							
							
							<tr>
								<th style="width: 150px;">
									物料描述：
								</th>
								<td colspan="3">
									<input type="text" class="text" style="width: 647px; line-height:22px; vertical-align:middle;" name="saveMaterialEdit.accessory"
									id="accessory"
									value="${materialEdit.accessory}" />
								</td>
							</tr>
							<tr id="e_file">
								<th style="width: 150px;" valign="middle">
									物料文件：
								</th>
								<td colspan="3">
									<input type="file" name="inputfile" 
										style="width: 225px; border: solid 1px #999999; height: 22px;" />
								</td>
							</tr>
							
							
							<s:if test="materialEdit.materialContent != null && materialEdit.materialContent != ''">
							<tr id="trID">
							    <th style="width: 150px;" valign="middle">
									&nbsp;&nbsp;&nbsp;&nbsp;
								</th>
								<td colspan="3">
									<a href="#" >${materialEdit.materialContent} </a> &nbsp;&nbsp;&nbsp;
									<a href="javascript:downloadFile('${materialEdit.materialContent}');" title="下载"> 
											<img id="iamge1" src="<%=request.getContextPath()%>/images/download.gif"
											align="middle" alt="下载" /> </a>
									<a href="#" onclick="javascript:deleteMaterial('${materialEdit.materialContent}');" title="删除"> 
											<img src="<%=request.getContextPath()%>/images/delete.gif"
											alt="删除" align="middle" /> </a>
								</td>
							</tr>
							</s:if>
							
			               </s:else>
					
						</table>
					</div>
					
					<s:if test="%{null!= materialEdit}">
					<div style="margin: 8px 0 0 150px;">
						<input type="button" class="btn-title" value="保存" 
                          onclick="addSubFrm();" />
						&nbsp;&nbsp;
						<input type="button" class="btn-title" value="取消"
							onclick="cancle('materiallist.action');" />
					</div>
					</s:if>
				   </div>
			   </div>
			</form>
		</div>
		<div id="organizeContent" class="menuContent"
			style="display: none; position: absolute;">
			<ul id="organizesTree" class="ztree" style="margin-top: 0;"></ul>
		</div>

		
		<!-- 顶部end -->
		<div id="tempDiv"></div>


		<!-- 底部start -->
		<jsp:include page="/jsp/common/bottom.jsp"></jsp:include>
		<!-- 底部end -->
		
		<script type="text/javascript">
			
			//获取后台数据显示组织架构
			var organizes =${flag};
			
			//组织架构初始化
			var organizeSetting = {
				view : {
					dblClickExpand : false
				},
				data : {
					simpleData : {
						enable : true
					}
				},
				callback : {
					beforeClick : beforeClick,
					onClick : organizeOnClick
				}
			};
				//页面加载
			$(function() {
				//设置组织架构弹出框
				$.fn.zTree.init($("#organizesTree"), organizeSetting, organizes);
			});
		
			//点击事件
			function beforeClick(treeId, treeNode) {
				var check = (treeNode && !treeNode.isParent);
				if (!check)
					alert("请选择下级节点！");
				return check;
			}
		
			//组织架构点击事件
			function organizeOnClick(e, treeId, treeNode) {
				var zTree = $.fn.zTree.getZTreeObj("organizesTree"), nodes = zTree.getSelectedNodes(), v = "";
				nodes.sort(function compare(a, b) {
					return a.id - b.id;
				});
				for ( var i = 0, l = nodes.length; i < l; i++) {
					v += nodes[i].name + ",";
				}
				if (v.length > 0)
					v = v.substring(0, v.length - 1);
				var orgNameObj = $("#showOrganize");
				orgNameObj.attr("value", v);
				//设置隐藏域中组织编号  
				$('#orgID').val(treeNode.id);
				hideMenu('organizeContent');
			}
		
			//隐藏组织架构
			function hideMenu(divId) {
				$("#" + divId).fadeOut("fast");
				$("body").unbind("mousedown", {
					tempDiv : divId
				}, onBodyDown);
			}
		
			//组织架构弹出窗
			function showMenu(objId, divId) {
				var cityObj = $("#" + objId);
				var cityOffset = $("#" + objId).position();
				$("#" + divId).css( {
					left : cityOffset.left + "px",
					top : cityOffset.top + cityObj.outerHeight() + "px"
				}).slideDown("fast");
				$("body").bind("mousedown", {
					tempDiv : divId
				}, onBodyDown);
			}
				//鼠标点击别的地方隐藏弹出属性菜单
			function onBodyDown(event) {
				var divId = event.data.tempDiv;
				if (!(event.target.id == "showOrganize" || $(event.target).parents(
						"#" + divId).length > 0)) {
					hideMenu(divId);
				}
			}
				//组织架构 showOrganize
		//	if(!paramIsNull('showOrganize'))
		//	{	
		//		alert('请选择用户所属组织架构！');
		//		return false;
		//	}
			
				//参数非空验证
			function paramIsNull(paramId){
				var temp = $('#'+paramId).val();
				if(null == temp || temp=='')
				{
					return false;
				}
				else{
					//文本框去左右空格重新赋值
					$('#'+paramId).val($.trim(temp));
					return true;
				}
			} 
			
			
			</script>
	</body>
</html>